$(document).ready(function() {
	queryUserGroups("",pageNo,"");//默认查询
});
var pageSize = 5;
var pageNo = 0;
var queryUserGroups = function(condition,pageNo,groupName){
	$("#jigou").hide();//影藏当前页面数据
	$("#loadingtable").show();//数据加载进度提示
	
	jQuery.post("/finance/usergroup/selUsergroups.do",{pageSize:pageSize,pageNo:pageNo,groupName:groupName},function(str){
			$("#loadingtable").hide();//隐藏数据加载进度提示
			$("#jigou").show();//影藏当前页面数据
			//拼表头
			var htmltxtHead = "<caption>用户组信息</caption>"
								+'<thead>'
								+'<tr>'
								+'<th width="120">序号</th>'
								+'<th width="120">用户组名称</th>'
								+'<th width="120">隶属公司名称</th>'
								+'<th width="120">隶属公司代码</th>'
								+'<th width="120">更新时间</th>'
								+'<th width="120">创建时间</th>'
								+'<th width="120">是否有效</th>'
								+'<th width="120">操作</th>'
								+'</tr>'
								+'</thead>'
			var htmltxtcontent = "";	
			var data = eval('(' + str + ')');
			htmltxtcontent += '<tbody>';
			if(data.data.length==0){
				htmltxtcontent += '<tr>'
				 				   +'<td width="120" colspan="8" align="center">对不起,没有您要查询的记录!</td>'
				 				   +'</tr>';
			}else{
				for (var i=0; i<data.data.length; i++) {
					htmltxtcontent += '<tr>'
				 				   +'<td width="120" align="center">'+ data.data[i].id +'</td>'
				 				   +'<td width="120" align="center">'+ data.data[i].groupName +'</td>'
				 				   +'<td width="120" align="center">'+ data.data[i].companyName +'</th>'
				 				   +'<td width="120" align="center">'+ data.data[i].companyCode +'</th>'
				 				   +'<td width="120">'+ data.data[i].updateTime +'</th>'
				 				   +'<td width="120">'+ data.data[i].createTime +'</th>'
				 				   +'<td width="120">'+ (data.data[i].isActive==1?"有效":"无效") +'</th>'
				 				   +'<td width="120"><div align="center">'
				 				  // +'<a href="#" target="">查看</a>|'
								   +'<a href="javascript:updateUserGroup('+data.data[i].id+',\''+data.data[i].groupName+'\');" target="_self">修改</a>|'
								   +'<a href="javascript:delUserGroup('+data.data[i].id+');" target="">删除</a>'
				 				   +'</div></th>'
						         +'</tr>';
				}
			}

			htmltxtcontent += '</tbody>';
			 $("#jigou").html(htmltxtHead+htmltxtcontent);
			  //分页器
			if(data.totalPageCount > 1){
				$("#pagingToolDiv").show();
	            $("#pagingToolDiv").html(PagingToolV2.getPagingCode('bottomgo',condition, 'queryUserGroups', data.totalPageCount,data.totalcount, pageNo));
            	$("#bottomgo").keydown(function(event){
                     if(event.keyCode==13){
                       if(parseInt($("#bottomgo").val())!=NaN){
                       	 if(data.totalPageCount<parseInt($("#bottomgo").val())){
                       	   parseInt($("#bottomgo").val(data.totalPageCount))
                       	 }
                         queryUsers('',parseInt($("#bottomgo").val()));
                       }
                     }
                });
            }else{
            	$("#pagingToolDiv").hide();
            }
        });
        
}

//模糊查询
function queryGroup(){
	queryUserGroups("",pageNo,$("#groupName").val());//模糊查询
}

//跳转到新增用户组页面
function toAddUserGroupPage(){
	window.open("/finance/views/console/addUserGroup.jsp","_self");
}

//修改用户组
function updateUserGroup(userGroupId){
	window.open("/finance/views/console/addUserGroup.jsp?userGroupId="+userGroupId,"_self");
}

//删除用户组
function delUserGroup(id){
	if (confirm("确认删除?该操作会删除与该用户组相关所有数据!!!")){
		jQuery.post("/finance/usergroup/delUserGroup.do",{id:id},function(str){
			var data = eval('(' + str + ')');
			if(data.success){
				jAlert("删除用户组成功!","提示");
				queryUserGroups("",0,"");//刷新界面
			}else{
				jAlert("删除用户组失败!","提示");			
			}
	    });
	}
}



//用户配置用户组
function addUserUserGroups(){
	jQuery.post("/finance/user/addUserUserGroups.do",{userId:"5",userGroupIdStr:"2,3,4,5"},function(str){
		var data = eval('(' + str + ')');
		if(data.success){
			jAlert("用户配置用户组成功!","提示");
		}else{
			jAlert("用户配置用户组失败!","提示");			
		}
    });
}
